package com.kexilo.core.common.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 认证配置属性
 *
 * @author Kexilo
 */
@Component
@ConfigurationProperties(prefix = "kexilo.auth")
public class AuthProperties {
    
    private TokenProperties token = new TokenProperties();
    private CaptchaProperties captcha = new CaptchaProperties();
    private SessionProperties session = new SessionProperties();
    private SecurityProperties security = new SecurityProperties();
    
    /**
     * Token配置
     */
    public static class TokenProperties {
        /** JWT密钥 */
        private String secret = "kexilo-jwt-secret-key-2024";
        
        /** 访问令牌过期时间（分钟） */
        private int accessTokenExpireTime = 120;
        
        /** 刷新令牌过期时间（天） */
        private int refreshTokenExpireTime = 30;
        
        /** 令牌头标识 */
        private String header = "Authorization";
        
        /** 令牌前缀 */
        private String prefix = "Bearer ";
        
        /** 每用户最大令牌数 */
        private int maxTokensPerUser = 5;
        
        /** 是否允许同时登录 */
        private boolean allowConcurrentLogin = true;

        // Getter and Setter methods
        public String getSecret() {
            return secret;
        }

        public void setSecret(String secret) {
            this.secret = secret;
        }

        public int getAccessTokenExpireTime() {
            return accessTokenExpireTime;
        }

        public void setAccessTokenExpireTime(int accessTokenExpireTime) {
            this.accessTokenExpireTime = accessTokenExpireTime;
        }

        public int getRefreshTokenExpireTime() {
            return refreshTokenExpireTime;
        }

        public void setRefreshTokenExpireTime(int refreshTokenExpireTime) {
            this.refreshTokenExpireTime = refreshTokenExpireTime;
        }

        public String getHeader() {
            return header;
        }

        public void setHeader(String header) {
            this.header = header;
        }

        public String getPrefix() {
            return prefix;
        }

        public void setPrefix(String prefix) {
            this.prefix = prefix;
        }

        public int getMaxTokensPerUser() {
            return maxTokensPerUser;
        }

        public void setMaxTokensPerUser(int maxTokensPerUser) {
            this.maxTokensPerUser = maxTokensPerUser;
        }

        public boolean isAllowConcurrentLogin() {
            return allowConcurrentLogin;
        }

        public void setAllowConcurrentLogin(boolean allowConcurrentLogin) {
            this.allowConcurrentLogin = allowConcurrentLogin;
        }
    }
    
    /**
     * 验证码配置
     */
    public static class CaptchaProperties {
        /** 是否启用验证码 */
        private boolean enabled = true;
        
        /** 验证码过期时间（分钟） */
        private int expireTime = 5;
        
        /** 验证码长度 */
        private int length = 4;
        
        /** 验证码宽度 */
        private int width = 120;
        
        /** 验证码高度 */
        private int height = 40;
        
        /** 验证码字符集 */
        private String charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

        // Getter and Setter methods
        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public int getExpireTime() {
            return expireTime;
        }

        public void setExpireTime(int expireTime) {
            this.expireTime = expireTime;
        }

        public int getLength() {
            return length;
        }

        public void setLength(int length) {
            this.length = length;
        }

        public int getWidth() {
            return width;
        }

        public void setWidth(int width) {
            this.width = width;
        }

        public int getHeight() {
            return height;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        public String getCharSet() {
            return charSet;
        }

        public void setCharSet(String charSet) {
            this.charSet = charSet;
        }
    }
    
    /**
     * 会话配置
     */
    public static class SessionProperties {
        /** 会话超时时间（分钟） */
        private int timeout = 30;
        
        /** 最大会话数 */
        private int maxSessions = 10;
        
        /** 会话并发控制 */
        private boolean concurrencyControl = true;

        // Getter and Setter methods
        public int getTimeout() {
            return timeout;
        }

        public void setTimeout(int timeout) {
            this.timeout = timeout;
        }

        public int getMaxSessions() {
            return maxSessions;
        }

        public void setMaxSessions(int maxSessions) {
            this.maxSessions = maxSessions;
        }

        public boolean isConcurrencyControl() {
            return concurrencyControl;
        }

        public void setConcurrencyControl(boolean concurrencyControl) {
            this.concurrencyControl = concurrencyControl;
        }
    }
    
    /**
     * 安全配置
     */
    public static class SecurityProperties {
        /** 登录失败最大次数 */
        private int maxLoginAttempts = 5;
        
        /** 账户锁定时间（分钟） */
        private int lockoutDuration = 30;
        
        /** 密码加密算法 */
        private String passwordEncoder = "BCrypt";
        
        /** 密码最小长度 */
        private int passwordMinLength = 6;
        
        /** 密码最大长度 */
        private int passwordMaxLength = 20;
        
        /** 是否启用密码复杂度检查 */
        private boolean passwordComplexityCheck = true;

        // Getter and Setter methods
        public int getMaxLoginAttempts() {
            return maxLoginAttempts;
        }

        public void setMaxLoginAttempts(int maxLoginAttempts) {
            this.maxLoginAttempts = maxLoginAttempts;
        }

        public int getLockoutDuration() {
            return lockoutDuration;
        }

        public void setLockoutDuration(int lockoutDuration) {
            this.lockoutDuration = lockoutDuration;
        }

        public String getPasswordEncoder() {
            return passwordEncoder;
        }

        public void setPasswordEncoder(String passwordEncoder) {
            this.passwordEncoder = passwordEncoder;
        }

        public int getPasswordMinLength() {
            return passwordMinLength;
        }

        public void setPasswordMinLength(int passwordMinLength) {
            this.passwordMinLength = passwordMinLength;
        }

        public int getPasswordMaxLength() {
            return passwordMaxLength;
        }

        public void setPasswordMaxLength(int passwordMaxLength) {
            this.passwordMaxLength = passwordMaxLength;
        }

        public boolean isPasswordComplexityCheck() {
            return passwordComplexityCheck;
        }

        public void setPasswordComplexityCheck(boolean passwordComplexityCheck) {
            this.passwordComplexityCheck = passwordComplexityCheck;
        }
    }

    // Main class getter and setter methods
    public TokenProperties getToken() {
        return token;
    }

    public void setToken(TokenProperties token) {
        this.token = token;
    }

    public CaptchaProperties getCaptcha() {
        return captcha;
    }

    public void setCaptcha(CaptchaProperties captcha) {
        this.captcha = captcha;
    }

    public SessionProperties getSession() {
        return session;
    }

    public void setSession(SessionProperties session) {
        this.session = session;
    }

    public SecurityProperties getSecurity() {
        return security;
    }

    public void setSecurity(SecurityProperties security) {
        this.security = security;
    }
}
